package com.ldl.distributelock.config;


import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CuratorConfig {

    @Bean
    public CuratorFramework curatorFramework(){
        //初始化一个重试策略。这里使用的是指数补偿策略。初始间隔时间  重试次数
        //重试次数可能是封装功能之一
        ExponentialBackoffRetry retry = new ExponentialBackoffRetry(10000, 3);
        //初始化客户端
        CuratorFramework client = CuratorFrameworkFactory.newClient("localhost:2181",retry);
        //客户端必须手动启动 否则有功能是用不了
        client.start();
        return client;
    }
}
